class FormasController < ApplicationController

  before_filter :login_required
  require_role ["admin","financiero","director"]
  
  def index
    store_location
    
    @formas = Forma.find(:all)
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @formas }
    end
  end
  
  def new
    @forma = Forma.new()
    
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @forma }
    end
  end

  def create
    @forma = Forma.new(params[:forma])

    respond_to do |format|
      if @forma.save
        flash[:success] = 'Forma de pago creada.'
        format.html { redirect_back_or_default :action=>'index', :controller=>'forma' }
        format.xml  { render :xml => @forma, :status => :created, :location => @forma }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @forma.errors, :status => :unprocessable_entity }
      end
    end    
  end
  
  def edit
    @forma = Forma.find(params[:id])
    
    respond_to do |format|
      format.html # edit.html.erb
      format.xml  { render :xml => @forma }
    end
  end
  
  def update
    @forma = Forma.find(params[:id])

    respond_to do |format|
      if @forma.update_attributes(params[:forma])
        flash[:success] = 'Forma de pago editada.'
        format.html { redirect_back_or_default :action=>'index', :controller=>'formas' }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @forma.errors, :status => :unprocessable_entity }
      end
    end
  end
  
  def destroy
    Forma.find(params[:id]).destroy
    redirect_back_or_default :action=>'index', :controller=>'formas'
  end
end
